

cc.Class({
    extends: cc.Component,

    properties: {
        title:{
            default:null,
            type:cc.Label,
        },
        desc:{
            default:null,
            type:cc.Label,
        },
        startButton:{
            default:null,
            type:cc.Node,
            tooltip:'开始按钮'
        },
        closeButton:{
            default:null,
            type:cc.Node,
            tooltip:'关闭按钮'
        }
    },
    
    setTitle(title){
        this.title.string = title;
    },

    setDesc(desc){
        desc = this._preprocessText(desc);
        this.desc.string = desc;
    },

    setStartButtonCallback(callback){
        this._startClickCallback = callback;
    },

    onStartButtonClick(){
        //
        this.showButtons(false);
        //
        if (this._startClickCallback)
            this._startClickCallback();
    },
    
    setCloseButtonCallback(callback){
        this._closeClickCallback = callback;
    },
    onCloseButtonClick(){
        //
        this.showButtons(false);
        //
        if (this._closeClickCallback)
            this._closeClickCallback();
    },

    onDestroy(){
        this.setStartButtonCallback(null);
        this.setCloseButtonCallback(null);
    },
    showButtons(bShow){
        this.startButton.active = this.closeButton.active = bShow;
    },
    _preprocessText(text){
        // 先去掉首位的空格
        text = text.trim();
        // 若字符超过max，则加上一定数量空格
        if (text.length > 13)
            text = '       ' + text;
        //
        return text;
    }
});
